using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;

using System.Reflection;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Forms;

using System.IO;
using System.Xml;
using TVC.Layout;
using TVC.Modules.CustomControl;

namespace TVC.Modules.Com
{
    /// <summary>
    /// Summary description for CustomWindowPanelControl.
    /// </summary>

    [Serializable()]
    public class POP : ModuleParent, IHostedApplication
    {
        bool _treeclick = true;
      
        string _strPermission = "";
        private TabControl tabControl1;
        private TabPage tbList;
        private TabPage tbDetail;
        private Label label2;
        private Label label1;
        private DataGridView dgvList;
        private BindingSource bisPOP;
        private Panel panel1;
        private IContainer components;
        private TreeView treeView1;
        private MultiColumnCombo mcbDB;
        private MultiColumnCombo mcbROLE_ID;
        private string strAction;
        private ContextMenu ctmGrid;
        private MenuItem menuItem1;
        private MenuItem mnuSaveLayout;
        private MenuItem mnuResetLayout;
        private MenuItem mnuShowFilter;
        GridLayout layout = null;

        public POP()
        {
            // This call is required by the WebGUI Form Designer.
            InitializeComponent();
            _strType = "POP";
            _dgvList = dgvList;
            _tabControl = tabControl1;
        }

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        int idAllowEditLanguage = 1;
        int idAddNew = 38;
        int idEdit = 39;
        int idDelete = 40;
        int idTransferIn = 41;
        int idTransferOut = 42;
        int idPrint = 43;
        int idToExcel = 263;



        protected override void AllowEditLanguage()
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                    x.DoubleClick += Control_DoubleClick;

                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    x.DoubleClick += Control_DoubleClick;
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            y.DoubleClick += Control_DoubleClick;
                    }
                }
            }

        }

        protected override void LoadLanguage(string language)
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            clsConfigurarion.GetLabel(this.ToString(), y, language);
                    }
                }
            }
            //clsConfigurarion.GetLabel(this.ToString(), tbDetail, language);
            //clsConfigurarion.GetLabel(this.ToString(), tbList, language);
            if (this.Parent is HeaderedPanel)
            {
                HeaderedPanel pln = this.Parent as HeaderedPanel;
                _title = clsConfigurarion.GetLabel(this.ToString(), "", null, language);
            }
        }
        public HostedToolBarElement[] GetToolBarElements()
        {
            ArrayList objElements = new ArrayList();
            if (IsPermis(idAddNew))
                objElements.Add(new HostedToolBarButton("Add New", new IconResourceHandle("Add.png"), "C"));
            if (IsPermis(idEdit))
                objElements.Add(new HostedToolBarButton("Edit", new IconResourceHandle("Edit.png"), "A"));
            if (IsPermis(idAddNew) || IsPermis(idEdit))
                objElements.Add(new HostedToolBarButton("Save", new IconResourceHandle("Save.png"), "S"));
            if (IsPermis(idAddNew))
                objElements.Add(new HostedToolBarButton("Copy", new IconResourceHandle("Copy.png"), "O"));
            if (IsPermis(idDelete))
                objElements.Add(new HostedToolBarButton("Delete", new IconResourceHandle("Delete.png"), "X"));

            objElements.Add(new HostedToolBarSeperator());
            if (IsPermis(idTransferIn))
                objElements.Add(new HostedToolBarButton("Import", new IconResourceHandle("Down.png"), "TI"));
            if (IsPermis(idPrint)) objElements.Add(new HostedToolBarButton("To XML", "To XML", new IconResourceHandle("Up.png"), "TO"));
            if (IsPermis(idToExcel)) objElements.Add(new HostedToolBarButton("To Excel", "To Excel", new IconResourceHandle("Excel.png"), "EXCEL"));

            objElements.Add(new HostedToolBarSeperator());
            objElements.Add(new HostedToolBarButton("Refresh", new IconResourceHandle("Refresh.png"), "R"));

            return (HostedToolBarElement[])objElements.ToArray(typeof(HostedToolBarElement));
        }


        #region Component Designer generated code
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.tabControl1 = new Gizmox.WebGUI.Forms.TabControl();
            this.tbList = new Gizmox.WebGUI.Forms.TabPage();
            this.dgvList = new Gizmox.WebGUI.Forms.DataGridView();
            this.bisPOP = new Gizmox.WebGUI.Forms.BindingSource(this.components);
            this.tbDetail = new Gizmox.WebGUI.Forms.TabPage();
            this.treeView1 = new Gizmox.WebGUI.Forms.TreeView();
            this.panel1 = new Gizmox.WebGUI.Forms.Panel();
            this.mcbDB = new TVC.Modules.CustomControl.MultiColumnCombo();
            this.mcbROLE_ID = new TVC.Modules.CustomControl.MultiColumnCombo();
            this.label1 = new Gizmox.WebGUI.Forms.Label();
            this.label2 = new Gizmox.WebGUI.Forms.Label();
            this.ctmGrid = new Gizmox.WebGUI.Forms.ContextMenu();
            this.menuItem1 = new Gizmox.WebGUI.Forms.MenuItem();
            this.mnuSaveLayout = new Gizmox.WebGUI.Forms.MenuItem();
            this.mnuResetLayout = new Gizmox.WebGUI.Forms.MenuItem();
            this.mnuShowFilter = new Gizmox.WebGUI.Forms.MenuItem();
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).BeginInit();
            this.tabControl1.SuspendLayout();
            this.tbList.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisPOP)).BeginInit();
            this.tbDetail.SuspendLayout();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // errProvider
            // 
            this.errProvider.BlinkStyle = Gizmox.WebGUI.Forms.ErrorBlinkStyle.BlinkIfDifferentError;
            // 
            // warnProvider
            // 
            this.warnProvider.BlinkStyle = Gizmox.WebGUI.Forms.ErrorBlinkStyle.BlinkIfDifferentError;
            // 
            // tabControl1
            // 
            this.tabControl1.Alignment = Gizmox.WebGUI.Forms.TabAlignment.Bottom;
            this.tabControl1.Appearance = Gizmox.WebGUI.Forms.TabAppearance.Workspace;
            this.tabControl1.Controls.Add(this.tbList);
            this.tabControl1.Controls.Add(this.tbDetail);
            this.tabControl1.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tabControl1.Location = new System.Drawing.Point(3, 3);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(754, 434);
            this.tabControl1.TabIndex = 0;
            // 
            // tbList
            // 
            this.tbList.Controls.Add(this.dgvList);
            this.tbList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbList.Location = new System.Drawing.Point(4, 22);
            this.tbList.Name = "tbList";
            this.tbList.Size = new System.Drawing.Size(746, 408);
            this.tbList.TabIndex = 0;
            this.tbList.Text = "List";
            // 
            // dgvList
            // 
            this.dgvList.AllowDrag = false;
            this.dgvList.AllowUserToAddRows = false;
            this.dgvList.AllowUserToDeleteRows = false;
            this.dgvList.AutoGenerateColumns = false;
            this.dgvList.BackgroundColor = System.Drawing.Color.White;
            this.dgvList.ColumnHeadersHeightSizeMode = Gizmox.WebGUI.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvList.ContextMenu = this.ctmGrid;
            this.dgvList.DataSource = this.bisPOP;
            this.dgvList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.dgvList.Location = new System.Drawing.Point(0, 0);
            this.dgvList.Name = "dgvList";
            this.dgvList.RowHeadersWidth = 25;
            this.dgvList.RowTemplate.DefaultCellStyle.FormatProvider = new System.Globalization.CultureInfo("en-US");
            this.dgvList.ShowFilterRow = true;
            this.dgvList.Size = new System.Drawing.Size(746, 408);
            this.dgvList.TabIndex = 0;
            // 
            // bisPOP
            // 
            this.bisPOP.DataSource = typeof(DTO.POPInfo);
            // 
            // tbDetail
            // 
            this.tbDetail.Controls.Add(this.treeView1);
            this.tbDetail.Controls.Add(this.panel1);
            this.tbDetail.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbDetail.Location = new System.Drawing.Point(0, 0);
            this.tbDetail.Name = "tbDetail";
            this.tbDetail.Size = new System.Drawing.Size(746, 408);
            this.tbDetail.TabIndex = 1;
            this.tbDetail.Text = "Detail";
            // 
            // treeView1
            // 
            this.treeView1.CheckBoxes = true;
            this.treeView1.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.treeView1.Location = new System.Drawing.Point(0, 45);
            this.treeView1.Name = "treeView1";
            this.treeView1.Size = new System.Drawing.Size(746, 363);
            this.treeView1.TabIndex = 1;
            this.treeView1.AfterCheck += new Gizmox.WebGUI.Forms.TreeViewEventHandler(this.treeView1_AfterCheck);
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.mcbDB);
            this.panel1.Controls.Add(this.mcbROLE_ID);
            this.panel1.Controls.Add(this.label1);
            this.panel1.Controls.Add(this.label2);
            this.panel1.Dock = Gizmox.WebGUI.Forms.DockStyle.Top;
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(746, 45);
            this.panel1.TabIndex = 0;
            // 
            // mcbDB
            // 
            this.mcbDB.AllowDrag = false;
            this.mcbDB.AutoScroll = false;
            this.mcbDB.AutoValidate = Gizmox.WebGUI.Forms.AutoValidate.Disable;
            this.mcbDB.Binding = null;
            this.mcbDB.DisplayField = null;
            this.mcbDB.DisplayRows = 0;
            this.mcbDB.Filter = false;
            this.mcbDB.KeyPressChk = false;
            this.mcbDB.Layout = null;
            this.mcbDB.Location = new System.Drawing.Point(323, 13);
            this.mcbDB.Lookup = null;
            this.mcbDB.MainForm = null;
            this.mcbDB.Name = "mcbDB";
            this.mcbDB.RowData = null;
            this.mcbDB.RowDatas = null;
            this.mcbDB.Size = new System.Drawing.Size(142, 20);
            this.mcbDB.TabIndex = 3;
            this.mcbDB.Value = "";
            this.mcbDB.ValueField = null;
            // 
            // mcbROLE_ID
            // 
            this.mcbROLE_ID.AllowDrag = false;
            this.mcbROLE_ID.AutoScroll = false;
            this.mcbROLE_ID.AutoValidate = Gizmox.WebGUI.Forms.AutoValidate.Disable;
            this.mcbROLE_ID.Binding = null;
            this.mcbROLE_ID.DisplayField = null;
            this.mcbROLE_ID.DisplayRows = 0;
            this.mcbROLE_ID.Filter = false;
            this.mcbROLE_ID.KeyPressChk = false;
            this.mcbROLE_ID.Layout = null;
            this.mcbROLE_ID.Location = new System.Drawing.Point(69, 13);
            this.mcbROLE_ID.Lookup = null;
            this.mcbROLE_ID.MainForm = null;
            this.mcbROLE_ID.Name = "mcbROLE_ID";
            this.mcbROLE_ID.RowData = null;
            this.mcbROLE_ID.RowDatas = null;
            this.mcbROLE_ID.Size = new System.Drawing.Size(142, 20);
            this.mcbROLE_ID.TabIndex = 3;
            this.mcbROLE_ID.Value = "";
            this.mcbROLE_ID.ValueField = null;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(24, 16);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(42, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Role ID";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(256, 16);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(53, 13);
            this.label2.TabIndex = 0;
            this.label2.Text = "Database";
            // 
            // ctmGrid
            // 
            this.ctmGrid.MenuItems.AddRange(new Gizmox.WebGUI.Forms.MenuItem[] {
            this.menuItem1,
            this.mnuShowFilter});
            // 
            // menuItem1
            // 
            this.menuItem1.Index = 0;
            this.menuItem1.MenuItems.AddRange(new Gizmox.WebGUI.Forms.MenuItem[] {
            this.mnuSaveLayout,
            this.mnuResetLayout});
            this.menuItem1.Text = "Layout";
            // 
            // mnuSaveLayout
            // 
            this.mnuSaveLayout.Index = 0;
            this.mnuSaveLayout.Tag = "SAVE";
            this.mnuSaveLayout.Text = "Save Layout";
            // 
            // mnuResetLayout
            // 
            this.mnuResetLayout.Index = 1;
            this.mnuResetLayout.Tag = "RESET";
            this.mnuResetLayout.Text = "Reset Layout";
            // 
            // mnuShowFilter
            // 
            this.mnuShowFilter.Index = 1;
            this.mnuShowFilter.Tag = "FILTER";
            this.mnuShowFilter.Text = "Filter Records";
            // 
            // POP
            // 
            this.Controls.Add(this.tabControl1);
            this.DockPadding.All = 3;
            this.Padding = new Gizmox.WebGUI.Forms.Padding(3);
            this.Size = new System.Drawing.Size(760, 440);
            this.Load += new System.EventHandler(this.POP_Load);
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).EndInit();
            this.tabControl1.ResumeLayout(false);
            this.tbList.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisPOP)).EndInit();
            this.tbDetail.ResumeLayout(false);
            this.panel1.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        #endregion


        #region IHostedApplication Members

        public void InitializeApplication()
        {
        }

      
        public void SetObject(object obj)
        {
        }


        public void OnToolBarButtonClick(HostedToolBarButton objButton, EventArgs objEvent)
        {
            try
            {
                sErr = "";
                string strAction = (string)objButton.Tag;

                BUS.POPControl ctr = new BUS.POPControl();
                switch (strAction)
                {
                    case "C":
                        AddNew(mcbROLE_ID);
                        break;
                    case "A":
                        editRecord(mcbROLE_ID);
                        break;
                    case "S":
                        saveRecord(mcbROLE_ID);
                        break;
                    case "O":
                        copy(mcbROLE_ID);
                        break;
                    case "X":
                        delete(mcbROLE_ID);

                        break;
                    case "TI": //trans in
                        importData();
                        break;
                    case "TO": //Tran out
                        export2Xml();
                        break;
                    case "EXCEL": //Tran out
                        export2Excel();
                        break;
                    case "R":
                        reloadList();
                        break;
                    case "P":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.POPInfo info = new DTO.POPInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            DataTable dt = DTO.POPInfo.ToDataTable();
                            dt.Rows.Add(info.ToDataRow(dt));
                            DataSet ds = new DataSet();
                            ds.Tables.Add(dt);
                            MainForm main = GetMainForm();
                            if (main != null)
                                main.PrintDataSet(ds, _strType);
                        }
                        break;
                }
              
                if (sErr == "")
                    ThrowMsg("Command: " + _processStatus);
            }
            catch (Exception ex)
            {
                ThrowMsg(ex.Message + Environment.NewLine + ex.Source);
            }
        }

        #region .::| Override Functions |::.
        protected override ModuleParent.ErrorStatus validateForm(ref string sErr)
        {
            ErrorStatus result = ErrorStatus.SUCCESS;
            sErr = "";

            if (mcbROLE_ID.Text.Trim() == "")
            {
                sErr = "Could not save blank, please check!";
                errProvider.SetError(mcbROLE_ID, sErr);
                strAction = _processStatus;
                sErr += "\n";
            }
            else errProvider.SetError(mcbROLE_ID, "");
            if (sErr != "") result = ErrorStatus.ERROR;
            return result;
        }
        protected override bool checkExists()
        {
            return new BUS.POPControl().IsExist(mcbROLE_ID.Value, mcbDB.Value);
        }
        protected override string addRecord(bool isDraft = false)
        {
            string sErr = "";
            DTO.POPInfo info = GetData();
            BUS.POPControl ctr = new BUS.POPControl();
            ctr.Add(info,ref sErr);
          
            return sErr;
        }
        protected override string updateRecord(bool isDraft = false)
        {
            string sErr = "";
            DTO.POPInfo info = GetData();
            BUS.POPControl ctr = new BUS.POPControl();
            sErr=ctr.Update(info);
            
            return sErr;
        }
        protected override string delRecord()
        {
            string sErr = "";
            DTO.POPInfo info = GetData();
            BUS.POPControl ctr = new BUS.POPControl();
            ctr.Delete(info.ROLE_ID, info.DB);
            
            return sErr;
        }
       
        protected override void refreshForm(string val)
        {
            mcbROLE_ID.Value = val;
            mcbDB.Value = val;
            SetPermission(val);
            ClearCheckTree();
        }
        protected override void reloadList()
        {
            GetMainForm().LoadDataTable(_strType);
            bisPOP.DataSource = GetMainForm().GetTable(_strType);
        }
        protected override void enableForm(bool val)
        {
            mcbROLE_ID.Enabled = val;
            mcbDB.Enabled = val;
           
            treeView1.Enabled = val;
        }
        protected override void loadRecord(object o)
        {
            if (o is DataRowView)
            {
                DTO.POPInfo inf = new DTO.POPInfo((DataRowView)o);
                SetData(inf);
            }
        }


        #endregion

      

        private DTO.POPInfo GetData()
        {
            return new DTO.POPInfo(mcbROLE_ID.Value
                , mcbDB.Value
                , "" //txtDEFAULT_VALUE.Text
                , GetPermission());

        }

        private string GetPermission()
        {

        
            string result = new string(' ', 800);
            foreach (TreeNode node in treeView1.Nodes)
            {
                int id = Convert.ToInt32(node.Name);
                string value = node.Checked ? "Y" : "N";
                result = result.Substring(0, id) + value + result.Substring(id + 1);
                GetPermission(node, ref result);
            }

            
            return result;
        }

        private void GetPermission(TreeNode node, ref string result)
        {
            foreach (TreeNode child in node.Nodes)
            {
                int id = Convert.ToInt32(child.Name);
                
                string value = child.Checked ? "Y" : "N";
                result = result.Substring(0, id) + value + result.Substring(id + 1);
                GetPermission(child, ref result);
            }
        }

        private void SetData(DTO.POPInfo info)
        {
            mcbROLE_ID.Value = info.ROLE_ID;
            mcbDB.Value = info.DB;
           
            _strPermission = info.PERMISSION;

            SetPermission(info.PERMISSION);

        }

        private void SetPermission(string p)
        {
            _treeclick = false;
            foreach (TreeNode node in treeView1.Nodes)
            {
                int id = Convert.ToInt32(node.Name);
                if (id < p.Length)
                {
                    if (p[id].ToString() == "Y")
                        node.Checked = true;
                    else node.Checked = false;
                }
                SetPermission(node, p);
            }
            _treeclick = true;

         
        }

        private void SetPermission(TreeNode node, string p)
        {
            foreach (TreeNode child in node.Nodes)
            {
                int id = Convert.ToInt32(child.Name);
                if (id < p.Length)
                {
                    if (p[id].ToString() == "Y")
                        child.Checked = true;
                    else child.Checked = false;
                }
                SetPermission(child, p);
            }
        }

        private void CheckTree(string Module, string Function, string Action)
        {
            _treeclick = false;
            foreach (TreeNode childNode in treeView1.Nodes)
            {

                if (childNode.Name == Module)
                {
                    _treeclick = false;
                    childNode.Checked = true;
                    TreeNode node = childNode;
                    foreach (TreeNode Node in node.Nodes)
                    {
                        if (Node.Name == Function && Node.Parent.Name == Module)
                        {
                            _treeclick = false;
                            Node.Checked = true;
                            TreeNode nodechild = Node;
                            foreach (TreeNode Nodech in nodechild.Nodes)
                            {
                                if (Nodech.Name == Action && Nodech.Parent.Name == Function && Nodech.Parent.Parent.Name == Module)
                                {
                                    _treeclick = false;
                                    Nodech.Checked = true;
                                }
                            }
                        }
                    }
                }
            }
            _treeclick = true;
        }


        private void ClearCheckTree()
        {
            foreach (TreeNode childNode in treeView1.Nodes)
            {
                childNode.Checked = false;
            }
        }

        #endregion

        private void POP_Load(object sender, EventArgs e)
        {

            enableForm(false);
            refreshForm("");
            string repotPath = String.Format("{0}{1}Security.xml", MainForm.ServerPath, Properties.Settings.Default.ConfigPath);
            LoadTreePermis(repotPath);
           
            LoadMultiCombo();


            if (idAllowEditLanguage >= GetMainForm().Permission.Length || GetMainForm().Permission[idAllowEditLanguage] == 'Y')
                AllowEditLanguage();

        }

        private void LoadTreePermis(string repotPath)
        {
            XmlDocument xml = new XmlDocument();
            xml.Load(repotPath);
            XmlElement xmldoc = xml.DocumentElement;
            treeView1.Nodes.Clear();
            XmlNodeList moduleNodeList = xmldoc.SelectNodes(@"POP[not(Function or Function='')]");
            foreach (XmlElement ele in moduleNodeList)
            {
                TreeNode moduleNode = treeView1.Nodes.Add(ele.SelectSingleNode("ID").InnerText, ele.SelectSingleNode("Module").InnerText, "");
                moduleNode.Tag = ele.SelectSingleNode("Address") != null ? ele.SelectSingleNode("Address").InnerText : "";
                XmlNodeList functionNodeList = xmldoc.SelectNodes(String.Format("POP[Module = '{0}' and Function and Function!='' and not(Action or Action='')]", ele.SelectSingleNode("Module").InnerText));
                foreach (XmlElement elefnc in functionNodeList)
                {
                    TreeNode functionNode = moduleNode.Nodes.Add(elefnc.SelectSingleNode("ID").InnerText, elefnc.SelectSingleNode("Function").InnerText, "");
                    functionNode.Tag = elefnc.SelectSingleNode("Address") != null ? elefnc.SelectSingleNode("Address").InnerText : "";
                    XmlNodeList actionNodeList = xmldoc.SelectNodes(String.Format("POP[Module = '{0}' and Function = '{1}' and Action and Action!='']", ele.SelectSingleNode("Module").InnerText, elefnc.SelectSingleNode("Function").InnerText));
                    foreach (XmlElement eleact in actionNodeList)
                    {
                        TreeNode actionNode = functionNode.Nodes.Add(eleact.SelectSingleNode("ID").InnerText, eleact.SelectSingleNode("Action").InnerText, "");
                        actionNode.Tag = eleact.SelectSingleNode("Address") != null ? eleact.SelectSingleNode("Address").InnerText : "";
                    }
                }
            }
        }

        private void LoadMultiCombo()
        {
            if (!GetMainForm().IsContainsTables("POG"))
                GetMainForm().LoadDataTable("POG");
            mcbROLE_ID.Binding = GetMainForm().GetTable("POG");
            GridLayout alayout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", "POG");
            GetMainForm().InitMultiComboBox(mcbROLE_ID, alayout, DTO.POGInfo.Field.ROLE_NAME.ToString(), DTO.POGInfo.Field.ROLE_ID.ToString());

            if (!GetMainForm().IsContainsTables("DB"))
                GetMainForm().LoadDataTable("DB");
            mcbDB.Binding = GetMainForm().GetTable("DB");
            GridLayout blayout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", "DB");
            GetMainForm().InitMultiComboBox(mcbDB, blayout, DTO.DBAInfo.Field.DESCRIPTION.ToString(), DTO.DBAInfo.Field.DB.ToString());
        }

    
        private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
        {
            if (_treeclick)
            {
                TreeNode node = e.Node;
                if (e.Node.Checked == true)
                {
                    if (node.Parent != null)
                    {
                        if (node.Parent.Parent != null)
                        {
                            _treeclick = false;
                            node.Parent.Parent.Checked = true;
                        }
                        _treeclick = false;
                        node.Parent.Checked = e.Node.Checked;
                    }
                }
                foreach (TreeNode childNode in node.Nodes)
                {
                    if (childNode.Checked != e.Node.Checked)
                        childNode.Checked = e.Node.Checked;
                }
            }
            else
            {
                _treeclick = true;
            }
        }

     

        
    }
}
